<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Writing Plugins</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="plugins.html" title="Chapter 18. Extending Smarty With Plugins">
<link rel="prev" href="plugins.naming.conventions.html" title="Naming Conventions">
<link rel="next" href="plugins.functions.html" title="Template Functions">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Writing Plugins</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="plugins.naming.conventions.html">Prev</a> </td>
<th width="60%" align="center">Chapter 18. Extending Smarty With Plugins</th>
<td width="20%" align="right"> <a accesskey="n" href="plugins.functions.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Writing Plugins">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="plugins.writing"></a>Writing Plugins</h2></div></div></div>
<p>
     Plugins can be either loaded by Smarty automatically from the
     filesystem or they can be registered at runtime via one of the
     register_* API functions. They can also be unregistered by using
     unregister_* API functions.
    </p>
<p>
     For the plugins that are registered at runtime, the name of the plugin
     function(s) does not have to follow the naming convention.
    </p>
<p>
     If a plugin depends on some functionality provided by another plugin
     (as is the case with some plugins bundled with Smarty), then the proper
     way to load the needed plugin is this:
    </p>
<pre class="programlisting">

&lt;?php
function smarty_function_yourPlugin(array $params, Smarty_Internal_Template $template)
{
  // load plugin depended upon
  $template-&gt;smarty-&gt;loadPlugin('smarty_shared_make_timestamp');
  // plugin code
}
?&gt;

    </pre>
<p>
     As a general rule, the currently evaluated template's Smarty_Internal_Template object is always passed to the plugins
     as the last parameter with two exceptions:
     </p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
      modifiers do not get passed the Smarty_Internal_Template object at all
     </p></li>
<li class="listitem"><p>
     blocks get passed
      <em class="parameter"><code>$repeat</code></em> after the Smarty_Internal_Template object to keep
     backwards compatibility to older versions of Smarty.
     </p></li>
</ul></div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="plugins.naming.conventions.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="plugins.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="plugins.functions.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Naming Conventions </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Template Functions</td>
</tr>
</table>
</div>
</body>
</html>
